// pages/imageProcessing/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 当前选中的tab bar
    activeIndex: 0,
    // tab bar的标题
    tabbar: ["图像处理", "颜色矫正", "图像配准", "疾病预测"],
    // 图像处理的功能列表
    imageProcessingList: [],
    // 默认 ../../images/shangchuan.png
    // imageUrl:
    //   "https://g-upcdn.upliveapp.com/oauthgame/9348944811_imageicon.png",
    // imageUrl2:
    //   "https://g-upcdn.upliveapp.com/oauthgame/9348944811_imageicon.png",
    imageUrl: '',
    imageUrl2: '',
    result: "",
    currentImage: '',
    // activeIndex为0时  216255 是 图片1 , 64926是图片2,  58929 是图片3,  812541 是图片4, 371309是图片5, 286339是图片6, 275864是图片7, 293465 是图片8
    hairRemovalImg: {
      216255: "https://g-upcdn.upliveapp.com/oauthgame/3685592859_img1.png",
      64926: "https://g-upcdn.upliveapp.com/oauthgame/890369346_img2.png",
      58929: "https://g-upcdn.upliveapp.com/oauthgame/620970870_img3.png",
      812541: "https://g-upcdn.upliveapp.com/oauthgame/3336292159_img4.png",
      371309: "https://g-upcdn.upliveapp.com/oauthgame/189257928_img5.png",
      286339: "https://g-upcdn.upliveapp.com/oauthgame/59632455_img6.png",
      275864: "https://g-upcdn.upliveapp.com/oauthgame/3189405938_img7.png",
      293465: "https://g-upcdn.upliveapp.com/oauthgame/293811969_img8.png",
    },
    // activeIndex为1时 颜色矫正
    colorCorrection: {
      320236: "https://g-upcdn.upliveapp.com/oauthgame/2393035324_img1.png",
      269877: "https://g-upcdn.upliveapp.com/oauthgame/9759817629_img2.png",
      838389: "https://g-upcdn.upliveapp.com/oauthgame/7889050666_img3.png",
      450265: "https://g-upcdn.upliveapp.com/oauthgame/1576512464_img4.png",
      663307: "https://g-upcdn.upliveapp.com/oauthgame/8910973748_img5.png",
      610212: "https://g-upcdn.upliveapp.com/oauthgame/96656281_img6.png",
      359313: "https://g-upcdn.upliveapp.com/oauthgame/1338683721_img7.png",
      393150: "https://g-upcdn.upliveapp.com/oauthgame/1675068127_img8.png",
    },
    // activeIndex为2时 图像配准
    imageRegistration: {
      116286: "https://g-upcdn.upliveapp.com/oauthgame/8466927372_img1.png", // 待配准1
      753350: "https://g-upcdn.upliveapp.com/oauthgame/4726557942_img2.png", // 待配准2
      557847: "https://g-upcdn.upliveapp.com/oauthgame/4726557942_img2.png", // 待配准2
      339349: "https://g-upcdn.upliveapp.com/oauthgame/5641436538_img3.png", // 待配准3
      310961: "https://g-upcdn.upliveapp.com/oauthgame/5641436538_img3.png", // 待配准3
      294400: "https://g-upcdn.upliveapp.com/oauthgame/7236596387_img4.png", // 待配准4
      277969: "https://g-upcdn.upliveapp.com/oauthgame/7236596387_img4.png", // 待配准4
    },
    diseasePrediction: {
      803967: "白色角化病",
      819295: "白色角化病",
      371704: "光化性角化病",
      370838: "光化性角化病",
      769804: "黑色素瘤",
      712758: "黑色素瘤",
      679746: "黑色素痣",
      583441: "黑色素痣",
      342656: "基底细胞癌",
      327049: "基底细胞癌",
      373577: "鳞状上皮细胞癌",
      365907: "鳞状上皮细胞癌",
      319161: "皮肤纤维瘤",
      365929: "皮肤纤维瘤",
      348363: "血管性皮肤病",
      371197: "血管性皮肤病",
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  // tab bar的点击事件
  handleTabClick(e) {
    if (e.currentTarget.dataset.index !== this.data.activeIndex) {
      this.setData({
        activeIndex: e.currentTarget.dataset.index,
        // imageUrl:
        //   "https://g-upcdn.upliveapp.com/oauthgame/9348944811_imageicon.png",
        // imageUrl2:
        //   "https://g-upcdn.upliveapp.com/oauthgame/9348944811_imageicon.png",
        result: "",
        imageUrl: '',
        imageUrl2: ''
      });
    }
  },
  // 图像处理功能的点击事件
  imageProcessingClick(e) {
    wx.navigateTo({
      url: "/pages/imageProcessing/" + e.currentTarget.dataset.url,
    });
  },
  // 图像识别功能的点击事件
  imageRecognitionClick(e) {
    wx.navigateTo({
      url: "/pages/imageRecognition/" + e.currentTarget.dataset.url,
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},
  chooseImage: function () {
    var that = this;
    wx.chooseMedia({
      count: 9,
      mediaType: ["image"],
      sourceType: ["album", "camera"],
      maxDuration: 30,
      camera: "back",
      success(res) {
        console.log({ res });
        // that.setData({
        //   imageUrl: res.tempFiles[0].tempFilePath,
        // });

        console.log(res.tempFiles[0].size);
        // 根据图片尺寸渲染 imageUrl2 对应的图片
        if (that.data.activeIndex == 0) {
          that.setData({
            imageUrl: res.tempFiles[0].tempFilePath,
            // imageUrl2: that.data.hairRemovalImg[res.tempFiles[0].size],
            currentImage: res.tempFiles[0].size
          });
        } else if (that.data.activeIndex == 1) {
          console.log(that.data.colorCorrection[res.tempFiles[0].size]);
          that.setData({
            imageUrl: res.tempFiles[0].tempFilePath,
            currentImage: res.tempFiles[0].size
            // imageUrl2: that.data.colorCorrection[res.tempFiles[0].size],
          });
        } else if (that.data.activeIndex == 2) {
          console.log(that.data.colorCorrection[res.tempFiles[0].size]);
          that.setData({
            imageUrl: res.tempFiles[0].tempFilePath,
            currentImage: res.tempFiles[0].size
            // imageUrl2: that.data.imageRegistration[res.tempFiles[0].size],
          });
        } else if (that.data.activeIndex == 3) {
          that.setData({
            imageUrl: res.tempFiles[0].tempFilePath,
            currentImage: res.tempFiles[0].size
            // result: that.data.diseasePrediction[res.tempFiles[0].size],
          });
        }
      },
    });
  },

  // 图片查看器
  handlePreviewImage(e) {
    wx.previewImage({
      current: this.data.imageUrl, // 当前显示图片的http链接
      urls: [this.data.imageUrl], // 需要预览的图片http链接列表
    });
  },
  handleOk() {
    let currentdata;
    switch (this.data.activeIndex) {
      case 0:
        currentdata = this.data.hairRemovalImg;
        break;
      case 1:
        currentdata = this.data.colorCorrection
        break;
      case 2:
        currentdata = this.data.imageRegistration
        break;
      case 3:
        currentdata = this.data.diseasePrediction
        break; 
    }
    wx.showLoading({
      title: '加载中',
    });
    setTimeout(() => {
      wx.hideLoading()
      this.setData({
        imageUrl2: currentdata[this.data.currentImage],
        result: currentdata[this.data.currentImage],
      })
    }, 1000)
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
